package com.weichat.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.model.Event_user;
import com.model.Propertr_user;
import com.model.User;
import com.service.Event_userService;
import com.service.Propertr_userService;
import com.service.UserService;

@RestController
public class SleepController {
	@Autowired
	Propertr_userService propertr_userService;
	@Autowired
	UserService userService;
	@Autowired
	Event_userService event_userService;
	@RequestMapping("/wsqgetup")
	public String getUp(HttpServletRequest req){
		String result="Y";
		String openid=(String)req.getSession().getAttribute("openid");
		User u=(User) req.getSession().getAttribute("user");
		//int u_id=129;
		int u_id=u.getId();
		Event_user eu=new Event_user();
		eu.setUserId(u.getId());
		eu.setEventId(1);
		eu.setType("Y");	
		event_userService.insertSelective(eu);
		//eu_id
		int eu_id=event_userService.selectEidByUidOrder(u_id).getEuId();
		Propertr_user p1=new Propertr_user();
		p1.setpId(1);
		p1.setCount(5); 
		p1.setuId(u_id);
		p1.setEuId(eu_id);
		p1.setEventName("早上起床");
		Propertr_user p2=new Propertr_user();
		p2.setpId(2);
		p2.setCount(100);
		p2.setuId(u_id);
		p2.setEuId(eu_id);
		p2.setEventName("早上起床");
		Propertr_user p3=new Propertr_user();
		p3.setpId(3);
		p3.setCount(100);
		p3.setuId(u_id);
		p3.setEuId(eu_id);
		p3.setEventName("早上起床");
		propertr_userService.insertSelective(p1);
		propertr_userService.insertSelective(p2);
		propertr_userService.insertSelective(p3);
		return result;
	}
	@RequestMapping("/wsqdarksleep")
	public String darksleep(HttpServletRequest req){
		String result="Y";
		String openid=(String)req.getSession().getAttribute("openid");
		//List<User> u=userService.selectByOpenId(openid);
		User u=(User) req.getSession().getAttribute("user");
		//int u_id=129;
		int u_id=u.getId();
		
		Event_user eu=new Event_user();
		eu.setUserId(u.getId());
		eu.setEventId(12);
		eu.setType("Y");	
		event_userService.insertSelective(eu);
		
		//eu_id
		int eu_id=event_userService.selectEidByUidOrder(u_id).getEuId();
//		Propertr_user p1=new Propertr_user();
//		p1.setpId(1);
//	//	p1.setCount(5); 
//		p1.setuId(u_id);
//		p1.setEuId(eu_id);
//		p1.setEventName("晚上上床睡觉");
		Propertr_user p2=new Propertr_user();
		p2.setpId(2);
		p2.setCount(100);
		p2.setuId(u_id);
		p2.setEuId(eu_id);
		p2.setEventName("晚上上床睡觉");
		Propertr_user p3=new Propertr_user();
		p3.setpId(3);
		p3.setCount(100);
		p3.setuId(u_id);
		p3.setEuId(eu_id);
		p3.setEventName("晚上上床睡觉");
		//propertr_userService.insertSelective(p1);
		propertr_userService.insertSelective(p2);
		propertr_userService.insertSelective(p3);
		return result;
	}

}
